home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / qbasicpg.zip / DIVIDE.BAS < prev    next >
BASIC Source File  |  1989-08-31  |  2KB  |  49 lines

  1. ' DIVIDE.BAS
  2. ' This program divides a string into three parts.
  3.  
  4. CONST BLANK$ = " "                    ' declare string constant
  5. char$ = ""                            ' initialize variables
  6. charCount% = 1
  7. nameCount% = 0
  8.  
  9. CLS                                   ' clear screen
  10.  
  11. PRINT "Enter name in the following format:  First Middle Last"
  12. INPUT "Name:  ", fullName$            ' get 3-part name from user
  13. nameLength% = LEN(fullName$)          ' determine length of name
  14.  
  15. ' loop until the entire three-part string has been stepped through
  16.  
  17. DO WHILE (charCount% <> nameLength% + 1)
  18.  
  19. '   read characters one at a time until a blank or end of string
  20. '     is encountered; assign characters to name$ variable
  21.  
  22.     DO WHILE (char$ <> BLANK$) AND (charCount% <> (nameLength% + 1))
  23.         char$ = MID$(fullName$, charCount%, 1)
  24.         name$ = name$ + char$
  25.         charCount% = charCount% + 1   ' track number of character read
  26.     LOOP
  27.  
  28.     char$ = ""                        ' reset char$
  29.     nameCount% = nameCount% + 1       ' increment nameCount%
  30.    
  31.     SELECT CASE nameCount%            ' assign string to name variables
  32.         CASE 1                        '   based on value of nameCount%
  33.             firstName$ = name$
  34.         CASE 2
  35.             middleName$ = name$
  36.         CASE 3
  37.             lastName$ = name$
  38.     END SELECT
  39.     name$ = ""                        ' reset name$
  40. LOOP
  41.  
  42. PRINT
  43. PRINT "Results of separation process:"
  44. PRINT
  45. PRINT "First name is "; firstName$    ' display results
  46. PRINT "Middle name is "; middleName$
  47. PRINT "Last name is "; lastName$
  48.  
  49.